﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

public partial class Move_User_Signup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void SignUpOnly_Click(object sender, EventArgs e)
    {
        string name = UserName.Text.Trim();
        string tel = UserTel.Text.Trim();
        string password = UserPass.Text.Trim();
        string email = UserMail.Text.Trim();
        if (name == "" || tel == "" || password == "" || email == "")
        {
            Label1.Text = "加'*'项为必填项！";
        }
        else
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
            try
            {
                conn.Open();
                string SQL = "insert into Users (uername,password,usertype,name,tel,email) values (@tel,@password,2,@name,@tel,@email)";

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = SQL;

                //依次添加每个字段的值
                SqlParameter ptel = new SqlParameter("@tel", SqlDbType.VarChar, 11);
                ptel.Value = tel;
                cmd.Parameters.Add(ptel);
                SqlParameter ppassword = new SqlParameter("@password", SqlDbType.VarChar, 20);
                ppassword.Value = password;
                cmd.Parameters.Add(ppassword);
                SqlParameter pname = new SqlParameter("@name", SqlDbType.NVarChar, 10);
                pname.Value = name;
                cmd.Parameters.Add(pname);
                SqlParameter pemail = new SqlParameter("@email", SqlDbType.NVarChar, 30);
                pemail.Value = email;
                cmd.Parameters.Add(pemail);

                int R = cmd.ExecuteNonQuery();  //R 的值就是返回影响表的行数
                if (R > 0)
                {
                    Session["ReturnPath"] = "Move_login.aspx";
                    Session["Message"] = "恭喜，注册成功！";
                    Response.Redirect("Success.aspx");
                }
                else
                {
                    Session["Message"] = "插入失败，请检查您的操作！";
                    Response.Redirect("Error.aspx");
                }
                //Session["ReturnPath"] = "Admin_Add.aspx";
                //Response.Redirect("Mid.aspx");
            }
            finally
            {
                conn.Close();
            }
        }

    }


    protected void SignUpWithFace_Click(object sender, EventArgs e)
    {
        string name = UserName.Text.Trim();
        string tel = UserTel.Text.Trim();
        string password = UserPass.Text.Trim();
        string email = UserMail.Text.Trim();

        if (name == "" || tel == "" || password == "" || email == "")
        {
            Label1.Text = "加'*'项为必填项！";
        }
        else
        {
            Session["UserName"] = name;
            Session["UserTel"] = tel;
            Session["UserPass"] = password;
            Session["UserMail"] = email;
            Response.Redirect("User_Face_Signup.aspx");
        }
    }
}